package net.pimpas.web.jsf.renderers.fieldset.html;

import java.io.IOException;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;

import net.pimpas.web.jsf.components.UIComponentPimpasBase;
import net.pimpas.web.jsf.components.fieldset.UIFieldset;
import net.pimpas.web.jsf.renderers.RendererBase;
import net.pimpas.web.jsf.renderers.util.html.HtmlRendererBase;
import net.pimpas.web.jsf.util.ComponentUtils;

public class HtmlFieldsetRenderer extends RendererBase {

	@Override
	public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
		if(!component.isRendered()) return;
		if(!ComponentUtils.isCorrectComponentType(component, UIFieldset.class)) return;
		
		ResponseWriter writer = context.getResponseWriter();
		writer.startElement("fieldset", component);
		
		HtmlRendererBase.writeBaseHtmlAttributes(context, (UIComponentPimpasBase) component);
	}
	
	@Override
	public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
		if(!component.isRendered()) return;
		if(!ComponentUtils.isCorrectComponentType(component, UIFieldset.class)) return;
		
		ResponseWriter writer = context.getResponseWriter();
		writer.endElement("fieldset");
	}
}